home *** CD-ROM | disk | FTP | other *** search
- /*
- * $RCSfile: undoFileKeyInsert.c,v $
- * $Revision: 1.1.1.1 $
- * $Date: 1996/05/04 21:56:03 $
- */
- /**********************************************************************
- * EXODUS Database Toolkit Software
- * Copyright (c) 1991 Computer Sciences Department, University of
- * Wisconsin -- Madison
- * All Rights Reserved.
- *
- * Permission to use, copy, modify and distribute this software and its
- * documentation is hereby granted, provided that both the copyright
- * notice and this permission notice appear in all copies of the
- * software, derivative works or modified versions, and any portions
- * thereof, and that both notices appear in supporting documentation.
- *
- * THE COMPUTER SCIENCES DEPARTMENT OF THE UNIVERSITY OF WISCONSIN --
- * MADISON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS" CONDITION.
- * THE DEPARTMENT DISCLAIMS ANY LIABILITY OF ANY KIND FOR ANY DAMAGES
- * WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
- *
- * The EXODUS Project Group requests users of this software to return
- * any improvements or extensions that they make to:
- *
- * EXODUS Project Group
- * c/o David J. DeWitt and Michael J. Carey
- * Computer Sciences Department
- * University of Wisconsin -- Madison
- * Madison, WI 53706
- *
- * or exodus@cs.wisc.edu
- *
- * In addition, the EXODUS Project Group requests that users grant the
- * Computer Sciences Department rights to redistribute these changes.
- **********************************************************************/
-
- #include "sysdefs.h"
- #include "ess.h"
- #include "checking.h"
- #include "trace.h"
- #include "error.h"
- #include "list.h"
- #include "pool.h"
- #include "tid.h"
- #include "io.h"
- #include "lock.h"
- #include "object.h"
- #include "msgdefs.h"
- #include "thread.h"
- #include "latch.h"
- #include "semaphore.h"
- #include "link.h"
- #include "lsn.h"
- #include "bf.h"
- #include "log.h"
- #include "volume.h"
- #include "logrecs.h"
- #include "openlog.h"
- #include "trans.h"
- #include "bitmap.h"
- #include "file.h"
- #include "consist.h"
- #include "undo.h"
- #include "io_extfuncs.h"
- #include "bf_extfuncs.h"
- #include "bm_extfuncs.h"
- #include "fi_extfuncs.h"
- #include "fi_macro.h"
- #include "fi_intfuncs.h"
- #include "log_extfuncs.h"
- #include "undo_extfuncs.h"
- #include "logaction.h"
- #include "util_funcs.h"
- #include "thread_globals.h"
- #include "bf_globals.h"
-
-
- void
- undoFileKeyInsert (
-
- LOGRECORDHDR *recordHeader
- )
- {
-
- register VOLREC *volRec;
- register PID *pid;
- register FOUR *insertLoc;
- register SHORTPID *key;
- register NODEPAGE *nodePage;
- register GROUPLINK *nodeLink;
- LOGRECORDINFO recordInfo;
- FORCEMARK forceMark;
- LSN lsn;
- LRC *lrc;
-
- TRPRINT(TR_IO, TR_LEVEL_1, ("lsn:%d", recordHeader->recordLSN.offset));
-
- /*
- * get a pointer to the page in the record
- */
- pid = (PID *) &(recordHeader->actionPid);
- TRPRINT(TR_IO, TR_LEVEL_2, ("pid:%d", pid->page));
-
- /*
- * get a pointer to the name in the record
- */
- insertLoc = (FOUR *) GET_LOG_IMAGE(recordHeader, 0);
- TRPRINT(TR_IO, TR_LEVEL_2, ("insertLoc:%d", *insertLoc));
-
- /*
- * get a pointer to the name in the record
- */
- key = (SHORTPID *) GET_LOG_IMAGE(recordHeader, 1);
- TRPRINT(TR_IO, TR_LEVEL_2, ("key:%d", *key));
-
- /*
- * check to see if the volume is mounted
- */
- if ((volRec = io_FindVolRec(pid->volid)) == NULL) {
-
- SM_ERROR(TYPE_FATAL, Active->errno);
- }
-
- /*
- * Read in first page of file and grab node type
- */
- if ((nodeLink = bf_ReadPage(UserBufGroup, pid, FILE_PAGE2SIZE, BF_SEM)) == NULL) {
-
- SM_ERROR(TYPE_FATAL, Active->errno);
- }
-
- /*
- * get a pointer to the node page
- */
- nodePage = (NODEPAGE *) nodeLink->bufFrame;
-
- /*
- * remove the key
- */
- FI_DeleteFromArray(nodePage, *insertLoc, *key);
- fi_PrintNode(nodePage);
-
- /*
- * increment the lrc on the page
- */
- lrc = &(((NODEHEADER *) nodeLink->bufFrame)->lrc);
- INCREMENT_LRC(lrc);
-
- /*
- * initialize the log information
- */
- recordInfo.type = LOG_REC_TYPE_COMPENSATION;
- recordInfo.action = LOG_ACTION_DELETE_FILE_KEY;
- recordInfo.imageCount = 2;
- recordInfo.actionPid = pid;
- recordInfo.actionLRC = lrc;
- recordInfo.imageSize[0] = sizeof(FOUR);
- recordInfo.imageData[0] = (VOID *) insertLoc;
- recordInfo.imageSize[1] = sizeof(SHORTPID);
- recordInfo.imageData[1] = (VOID *) key;
- recordInfo.flags = NOFLAGS;
- recordInfo.nextUndoLSN = recordHeader->previousLSN;
-
- /*
- * write the record to the log
- */
- if ((forceMark = writeLogRecord((TRANSREC *) Active->transRec, &recordInfo,
- &lsn, NOFLAGS)) < 0) {
-
- SM_ERROR(TYPE_FATAL, Active->errno);
- }
-
- /*
- * mark the page dependency
- */
- DEPEND_LOG(nodeLink->pageHash, forceMark, &lsn, lrc);
-
- /*
- * release the page semaphore
- */
- signalSemaphore( &(nodeLink->pageHash->semaphore) );
-
- /*
- * release and dirty the page
- */
- bf_UnfixPage(nodeLink, BF_DEFAULT, TRUE);
- }
-
-
-
- void
- undoFileKeyDelete (
-
- LOGRECORDHDR *recordHeader
- )
- {
-
- VOLREC *volRec;
- SHORTPID *key;
- FILEKEYLOGINFO *fileKeyLogInfo;
- SHORTPID dummy;
-
- TRPRINT(TR_IO, TR_LEVEL_1, ("lsn:%d", recordHeader->recordLSN.offset));
-
- /* get a pointer to the key to insert */
- key = (SHORTPID *) GET_LOG_IMAGE(recordHeader, 1);
- TRPRINT(TR_IO, TR_LEVEL_2, ("key:%d", *key));
-
- /* get a pointer to the fid and lg obj info */
- fileKeyLogInfo = (FILEKEYLOGINFO *) GET_LOG_IMAGE(recordHeader, 2);
- TRPRINT(TR_IO, TR_LEVEL_2, ("fid:%d:%d", fileKeyLogInfo->fid.pid.page, (int) (fileKeyLogInfo->fid.pid.volid) ));
-
- /* check to see if the volume is mounted */
- if ((volRec = io_FindVolRec(fileKeyLogInfo->fid.pid.volid)) == NULL) {
-
- SM_ERROR(TYPE_FATAL, Active->errno);
- }
- /*
- * Logically insert a new page into the file
- */
-
- /* insert the page in the file */
- if (fi_InsertPage(UserBufGroup, &(fileKeyLogInfo->fid),
- *key, fileKeyLogInfo->largeObjOnPage, &dummy)) {
- SM_ERROR(TYPE_FATAL, Active->errno);
- }
-
- /* log a compensation for the insert */
- if (FI_LogKeyInsertDone(&(fileKeyLogInfo->fid), *key, recordHeader->previousLSN)) {
- SM_ERROR(TYPE_FATAL, Active->errno);
- }
- }
-
- void
- undoFileKeyInsertDone(
-
- LOGRECORDHDR *recordHeader
- )
- {
- FID *fid;
- SHORTPID *key;
- PID pid;
- VOLREC *volRec;
- TRANSREC *transRec = (TRANSREC*) Active->transRec;
-
- CHECK_TRANSREC_MAGIC(transRec);
-
- /* get a pointer to the fid and lg obj info */
- fid = (FID *) GET_LOG_IMAGE(recordHeader, 0);
- TRPRINT(TR_IO, TR_LEVEL_2, ("fid:%d:%d", fid->pid.page, (int) (fid->pid.volid) ));
-
- /* get a pointer to the key to insert */
- key = (SHORTPID *) GET_LOG_IMAGE(recordHeader, 1);
- TRPRINT(TR_IO, TR_LEVEL_2, ("key:%d", *key));
-
- /*
- * The following steps are a little delicate. The first thing
- * is to deallocate the page and log the deallocation. This
- * is a normal log record. Then we mark the page as no longer
- * slotted. This is also logged. Finally, we remove the page from
- * the file. This is logged as a compensation record wrapping
- * around the the previous records.
- */
-
- /* log removing the page from the bitmap */
- pid.page = *key;
- pid.volid = fid->pid.volid;
- #ifdef JUNK
- if (io_DeallocPages(SLOTTED_PAGE2SIZE, 1, &pid, NULL, TRUE, TRUE) != esmNOERROR) {
- #endif
- if (io_FakeDeallocPages(SLOTTED_PAGE2SIZE, 1, &pid, &(transRec->pageDeallocList), PAGE_SLOTTED) != esmNOERROR) {
- SM_ERROR(TYPE_FATAL, Active->errno);
- }
- bf_InvalidatePage(&pid);
-
-
- /* mark the page as no longer slotted */
- if ((volRec = io_FindVolRec(pid.volid)) == NULL) {
- SM_ERROR(TYPE_FATAL, Active->errno);
- }
- if (io_MarkPage(volRec, &pid, PAGE_SLOTTED, FALSE) != esmNOERROR) {
- SM_ERROR(TYPE_FATAL, Active->errno);
- }
-
- if (fi_DeletePage(UserBufGroup, fid, *key, recordHeader->previousLSN) != esmNOERROR) {
- SM_ERROR(TYPE_FATAL, Active->errno);
- }
-
- return;
- }
-